/*
* $Id: Word.java 69 2012-12-11 11:54:51Z Denis.Skalsky@gmail.com $
*/
package com.globallogic.skalskyy.javabasic.anagram;

import java.util.Arrays;

import com.globallogic.skalskyy.javabasic.inputdata.ConsoleReader;
import com.globallogic.skalskyy.javabasic.inputdata.DataValidator;

/**
* Word checks the input string is an anagram.
* @author $Author: denis.skalsky@gmail.com $
* @version $Revision: 40 $
*/
public class Word {
	
	private DataValidator dateValidator = new DataValidator();
	
	public void setConsoleReader() {
		this.dateValidator.setIncomingData(
				new ConsoleReader(ConsoleReader.ConsoleCommandPrompt.TWOWORDS));		
	}

	public String[] getInputtedWords() {
		return this.dateValidator.getTwoWords();
	}
	
	/**
	* Check that the input string is an anagram.
	* @param candidate for an anagram
	* @return result if it's an anagram then result = true
	*/
	public static boolean isAnAnagram(String original, String anagram) {
		if (original.length() != anagram.length()) {
			return false;
		};
		
		char[] originalLetters = original.toCharArray();
		Arrays.sort(originalLetters);
						
		char[] anagramLetters = anagram.toCharArray();
		Arrays.sort(anagramLetters);
		
		return Arrays.equals(originalLetters, anagramLetters);
	}
}